//==============================================================================
// SearchResult.hh
//
// Implements classes to abstract the process of searching a sequence or group of 
// sequences away from the actual search algorithm so that code can be written
// without too much knowledge of the underlying algorithm. 
//
//==============================================================================
//.......1.........2.........3.........4.........5.........6.........7.........8
//

#ifndef _SEQUENCE_SEARCH_ENGINE
#define _SEQUENCE_SEARCH_ENGINE

#include "LocalSTL.hh"
#include "Table.hh"
#include "Sequence.hh"
#include "ParseUtils.hh"
#include "PrintUtils.hh"
#include "RandomNumberGenerator.hh"
//#include "LogStream.hh"

//-----------------------------------------------------------------------------
// * SearchResult
//-----------------------------------------------------------------------------
// Class designed to capture the essential components of a search result.  
//
class SearchResult{
public:
  // Indices of the subject and query this result came from.  
  long   mSubjectIdx;
  long   mQueryIdx;

  // Locations of the query within the subject
  long   mSubjectLocation; // KJD Is this confusing?  Should it be mQueryLocation?

  // Location of hit within the query. 
  long   mQueryLocation;

  //int    mIdentitiesNum;

  void   Print(ostream &fout);
  void   Print(){Print(cout);};
  void   ExtractQueryLocFromName();
  void   ExtractQueryLocFromName(string&,long&);
};


//-----------------------------------------------------------------------------
// * SearchResultVec
//-----------------------------------------------------------------------------
//
// Encapsulates methods to work on a set of search results
//
class SearchResultVec : public vector<SearchResult>{
public:

  SearchResultVec();
  ~SearchResultVec(){};

  string mQueryName;
  string mDatabaseName;   // alternately, database name. 

  // Subject and query names
  vector<string> mSubjects;
  vector<string> mQueries;

  // KJD this keyword functionality should be replaced with some 
  // kind of delimited string in a more generalized routine.

  void GrowVec();
  void ParseView0(string FileName);
  void ParseView0HTML(string FileName);
  void Print(){Print(cout);};
  void Print(ostream &fout);
  void PrintExpectFiltered(ostream &fout,double cutoff);

  void SortBySubjectIdx();
  void SortBySubjectLoc();

  void SortByQueryIdx();

  void SortByExpect();
  void GetSubjectList(vector<string>&subjectList);
  void GetQueryList(vector<string>&queryList);

  void FindLongestContiguousSpan(long &start,long &end);

  void PrintLocationPlot(int PlotLength,int PlotCutoff,SequenceVector &Sources){
	 PrintLocationPlot(cout,PlotLength,PlotCutoff,Sources);
  }

  void PrintLocationPlot(ostream &fout,int PlotLength,
								 int PlotCutoff,Sequence &Sources);

  void PrintLocationPlot(ostream &fout,int PlotLength,
								 int cutoff,SequenceVector &Sources);
								 
  void PrintLocationPlot(ostream &fout,int PlotLength,SequenceVector &Sources){
	 PrintLocationPlot(fout,PlotLength,0,Sources);
  }

  void ZeroArray(int*,int length);
  long GetMaxSubjectLength(SequenceVector &Sources);

  void PrintBinnedPlotHits(ostream&fout,string &Name,long SubjectLength,
									int* PlotBins,int PlotLength,int MaxPlotLength);

  char GetPrintSymbol(int size);

};

#endif

